home *** CD-ROM | disk | FTP | other *** search
/ Hyper Stacks 1994 May / Hyper Stacks (Pacific HiTech)(1994)[Mac].iso / HyperTalk / RegionPackage / Picture Window ƒ / WDEF Demo.c < prev    next >
C/C++ Source or Header  |  1990-12-10  |  3KB  |  150 lines

  1. /* trivial demo of Picture Window WDEF, Nigel Perry 90 */
  2. /* Comments? This program is trivial… */
  3.  
  4. #include "PictWindow.h"
  5. #include "WDEFGlobals.h"
  6.  
  7. #define NIL ((void *)0)
  8. #define FRONTWIN ((WindowPtr)-1)
  9.  
  10. /* used to check if window was framed */
  11. framed(w, wl)
  12. WindowPtr w, *wl;
  13. {    int i;
  14.  
  15.     for(i = 0; i < 16; i++)
  16.     {    if(w == *wl++)
  17.             return(i & PW_AddFrame);
  18.     }
  19.     
  20.     return(0);
  21. }
  22.  
  23. main()
  24. {    int i, v, h, stop;
  25.     Rect r1, r2;
  26.     WindowPtr w[16], wind;
  27.     PicHandle p1, p2, p3, p4;
  28.     EventRecord event;
  29.     WDEFGlobals *gp;
  30.     Rect size;
  31.     
  32.     InitGraf(&thePort);
  33.     InitFonts();
  34.     FlushEvents(everyEvent,0);
  35.     InitWindows();
  36.     InitMenus();
  37.     TEInit();
  38.     InitDialogs(NIL);
  39.     InitCursor();
  40.  
  41.     if(!doDialog()) return;
  42.  
  43.     if(GetWDEFGlobals(true, &gp)) return;
  44.     
  45.     /* some pictures to draw */
  46.     p1 = (PicHandle)GetResource('PICT', 103);
  47.     p2 = (PicHandle)GetResource('PICT', 104);
  48.     p3 = (PicHandle)GetResource('PICT', 101);
  49.     p4 = (PicHandle)GetResource('PICT', 102);
  50.  
  51.     r1.top = 16; r1.left = 16; r1.bottom = 106; r1.right = 86;
  52.     
  53.     i = 0;
  54.     gp->pic = p1;
  55.     gp->frame = p2;
  56.     gp->flags.clonePic = gp->flags.cloneFrame = false;
  57.     gp->flags.sharePic = gp->flags.shareFrame = true;
  58.     
  59.     for(v = 0; v <= 240; v += 80)
  60.         for(h = 0; h <= 384; h += 128)
  61.         {    r2 = r1;
  62.             OffsetRect(&r2, h, v);
  63.             if(i == 12) { gp->pic = p3; gp->frame = p4; }
  64.             w[i] = NewWindow(NIL, &r2, "\p", true, PictWDEF | i, FRONTWIN, false, 0);
  65.             /* NewWindow() will not draw the window's picture,
  66.                 calling CheckUpdate() will fix this - all subsequent
  67.                 redraws will be handled automatically by QD
  68.              */
  69.             CheckUpdate(&event);
  70.             i++;
  71.         }
  72.  
  73.     stop = 0;
  74.     size.left = 4; size.right = 32767;
  75.     size.top = 4; size.bottom = 32767;
  76.     r1.top = 0; r1.left = 0; r1.bottom = 32767; r1.right = 32767;
  77.     
  78.     while(!stop)
  79.     {    if( GetNextEvent(everyEvent, &event) )
  80.             switch( event.what )
  81.             {    case updateEvt:
  82.                     BeginUpdate((WindowPtr)event.message);
  83.                     EndUpdate((WindowPtr)event.message);
  84.                     break;
  85.                 case keyDown:
  86.                     stop = 1;
  87.                     break;
  88.                 case mouseDown:
  89.                     switch( FindWindow(event.where, &wind) )
  90.                     {    case inContent:
  91.                             if( wind != FrontWindow() ) SelectWindow(wind);
  92.                             else
  93.                             {    SetPort(wind);
  94.                                 FillRect(&r1, gray);
  95.                                 while( StillDown() );
  96.                                 EraseRect(&r1);
  97.                             }
  98.                             break;
  99.                         case inDrag:
  100.                             if( framed(wind, w) )
  101.                             {    if( wind != FrontWindow() )
  102.                                     SelectWindow(wind);
  103.                                 else
  104.                                     DragWindow(wind, event.where, &screenBits.bounds);
  105.                             }
  106.                             else if( event.modifiers & 0x0800 ) /* option key */
  107.                             {    /* in asm as GrowWindow returns a long and 
  108.                                     SizeWindow wants two ints… */
  109.                                 asm
  110.                                 {    subq.l    #4,a7
  111.                                     move.l    wind,-(a7)
  112.                                     move.l    event.where,-(a7)
  113.                                     pea        size
  114.                                     _GrowWindow
  115.                                     move.l    (a7)+,d0
  116.                                     beq.s        @nogrow
  117.                                     move.l    wind,-(a7)
  118.                                     move.l    d0,-(a7)
  119.                                     move.w    #0,-(a7)
  120.                                     _SizeWindow
  121.                                     ; CopyRgn(strucRgn, updateRgn) -> invalidate
  122.                                     ; whole window area
  123.                                     move.l    wind,a0
  124.                                     move.l    OFFSET(WindowRecord,strucRgn)(a0),-(a7)
  125.                                     move.l    OFFSET(WindowRecord,updateRgn)(a0),-(a7)
  126.                                     _CopyRgn
  127.                                 nogrow:
  128.                                 }
  129.                             }
  130.                             else
  131.                                 DragWindow(wind, event.where, &screenBits.bounds);
  132.                             break;
  133.                         default:
  134.                             break;
  135.                     }
  136.                     break;
  137.                 default:
  138.                     break;
  139.             }
  140.     }
  141.                             
  142.  
  143.     /* clean up */    
  144.     for(i = 0; i < 16; i++) DisposeWindow(w[i]);
  145.     ReleaseResource(p1);
  146.     ReleaseResource(p2);
  147.     ReleaseResource(p3);
  148.     ReleaseResource(p4);
  149.     
  150. }